//
//  VOHMVConnect.m
//  VoiceOfHeart
//
//  Created by 吉龙 on 16/8/18.
//  Copyright © 2016年 吉龙. All rights reserved.
//

#import "VOHMVConnect.h"

@implementation VOHMVConnect


+(void)AFNrequestDataWithUrl:(NSString *)url requestsHeader:(NSDictionary *)header params:(NSMutableDictionary *)params HTTPMeod:(NSString *)meod sendingBlock:(SendingDataBlock)block{
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
    //添加请求头
    for (NSString *key in header.allKeys) {
        [request addValue:header[key] forHTTPHeaderField:key];
    }
    
    //get请求
    
    NSComparisonResult comResult1 = [meod caseInsensitiveCompare:@"GET"];
    if (comResult1 == NSOrderedSame) {
        [request setHTTPMethod:meod];
    
    //添加参数,将参数拼接到url后面
    NSMutableString *paramsString = [NSMutableString string];
    
    NSArray *allkeys = [params allKeys];
    
    for (NSString *key in allkeys) {
        NSString *value = [params objectForKey:key];
        [paramsString appendFormat:@"&%@=%@", key,value];
    }
    if (paramsString.length > 0) {
        //重新设置url
        [request setURL:[NSURL URLWithString:[url stringByAppendingString:paramsString]]];
    }
    
}
    NSURLSessionConfiguration *configuration =[NSURLSessionConfiguration defaultSessionConfiguration];
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
    NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        block(responseObject);
    }];
    
    [dataTask resume];
}

@end
